package com.gecco.crawler.pipeline;

import com.gecco.crawler.htmlbean.AllSort;
import com.gecco.crawler.htmlbean.Category;
import com.geccocrawler.gecco.annotation.PipelineName;
import com.geccocrawler.gecco.pipeline.Pipeline;
import com.geccocrawler.gecco.request.HttpRequest;
import com.geccocrawler.gecco.scheduler.SchedulerContext;
import com.geccocrawler.gecco.spider.HrefBean;

import java.util.ArrayList;
import java.util.List;

@PipelineName("allSortPipeline")
public class AllSortPipeline implements Pipeline<AllSort> {
	
    public void process(AllSort allSort) {
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~ allSort管道 ~~~~~~~~~~~~~~~~~~~~~~~~~");
        List<Category> categorys = new ArrayList<Category>();
        categorys.addAll(allSort.getInternet());
        categorys.addAll(allSort.getElectric());
        categorys.addAll(allSort.getMobileInternet());
        categorys.addAll(allSort.getNetGame());
        categorys.addAll(allSort.getNetMarket());
        for(Category category : categorys) {
            List<HrefBean> hrefs = category.getCategorys();
            for(HrefBean href : hrefs) {
            	String subUrl = href.getUrl();
                System.out.println(href.getTitle() + " url: " + subUrl);
                HttpRequest currRequest = allSort.getRequest();
                SchedulerContext.into(currRequest.subRequest(subUrl));
            }
            System.out.println("-----------------------------------------------------------");
        }
        System.out.println();
    }
}
